<template>
  <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
    <a-form>
      <a-form-item
          label="参选企业"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
      >
        <a-input  :placeholder="(this.enterprise)" :disabled="true"/>
      </a-form-item>
      <a-form-item
        :label="$t('title')"
        :labelCol="{span: 7}"
        :wrapperCol="{span: 10}"
        :required="true"
      >
        <a-input :placeholder="$t('titleInput')" v-model="userName">
          <a-icon slot="prefix" type="user" />
        </a-input>
      </a-form-item>
      <a-form-item
          label="密码"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input-password  placeholder="密码不小于6位" v-model="userPass"/>
      </a-form-item>
      <a-form-item
          label="姓名"
          :labelCol="{span: 7}"
          :wrapperCol="{span: 10}"
          :required="true"
      >
        <a-input placeholder="负责人姓名" v-model="userRealName"/>
      </a-form-item>
      <a-form-item
        :label="$t('customer')"
        :labelCol="{span: 7}"
        :wrapperCol="{span: 10}"
        :required="true"
      >
        <a-input :placeholder="$t('customerInput')" v-model="userPhone">
          <a-icon slot="prefix" type="phone" />
        </a-input>
      </a-form-item>


      <a-form-item style="margin-top: 24px" :wrapperCol="{span: 10, offset: 7}">
        <a-button type="primary" @click="addDeclarant">{{$t('submit')}}</a-button>
        <a-button style="margin-left: 8px" @click="goBack">返回</a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import Axios from 'axios'

export default {
  name: 'Declarant',
  i18n: require('./i18n'),
  data () {
    return {
      url: this.$store.state.apiUrl + ':' + this.$store.state.apiPort,
      value: 1,
      userName: '',
      userPass: '',
      userRealName: '',
      userPhone: ''
    }
  },
  computed: {
    desc() {
      return this.$t('pageDesc')
    },
    enterprise() {
      return this.$route.query.enterprise
    }
  },
  methods: {
    // 添加申报人
    addDeclarant() {
      Axios.post(this.url + '/pxManagerSystem/insertCompanyUsers', {
        "company_username": this.userName,
        "company_userpass": this.userPass,
        "company_userrealname": this.userRealName,
        "company_userphone": this.userPhone
      }).then(res => {
        if (res.data.state !== 200) {
          this.$message.error('添加出错，请检查网络连接')
          console.log(res)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    goBack() {
      window.history.back()
    }
  }
}
</script>

<style scoped>

</style>
